#include "getfriendresponse.h"




GetFriendIdResponse::GetFriendIdResponse(QObject *parent) :
    Network::JSONResponse(parent)
{
}


GetFriendIdResponse::~GetFriendIdResponse()
{

}


void GetFriendIdResponse::parse(const QVariant &data)
{
    if (data.type() != QVariant::Map) {
        setError(Network::Response::Property, QString("The \"data\" field isn't compatible"));
        return;
    }

    QVariantMap map = data.toMap();

    /*
    if (!map.contains("tot")) {
        setError(Network::Response::Property, QString("The \"tot\" field is missing"));
        return;
    }

    QVariant total = map.value("tot");
    if (total.type() != QVariant::Int) {
        setError(Network::Response::Property, QString("The \"tot\" field isn't compatible"));
        return;
    }
    */

    if (!map.contains("list")) {
        setError(Network::Response::Property, QString("The \"list\" field is missing"));
        return;
    }

    QVariant list = map.value("list");
    if (list.type() != QVariant::List) {
        setError(Network::Response::Property, QString("The \"list\" field isn't compatible"));
        return;
    }

    parseIdList(list.toList());
}


void GetFriendIdResponse::parseIdList(const QVariantList &list)
{
    bool ok;
    foreach (QVariant item, list) {
        qint64 id = item.toString().toLongLong(&ok);
        if (!ok) {
            setError(Response::Property, "The value of \"uid\" isn't competible");
            continue;
        }
        m_idList.append(id);
    }
}


